
/* 

function queue(nums) {
	let promise = Promise.resolve();
	nums.map(n => {
		promise = promise.then(v => {
			return new Promise((resolve, reject) => {
				console.log(n);
				if(n != 3)  {
					resolve();
				} else {
					reject(`n = ${n}`)
				}
			}).catch(err => {
				console.warn(err)
			});
		});
	})
}

*/

function queue(nums) {
  return nums.reduce((promise, n) => {
    return promise.then(() => {
      return new Promise((resolve, reject) => {
        console.log(n);
		if(n != 3)  {
			resolve();
		} else {
			reject(`n = ${n}`)
		}
      });
    });
  }, Promise.resolve());
}

console.log( queue([1, 2, 3, 4, 5]) )

function queue2 (promises) {
  promises.reduce((promise, next) => promise.then(next), Promise.resolve())
}
